home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / front.lha / front / m2c / Actions.c next >
C/C++ Source or Header  |  1992-08-18  |  7KB  |  312 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_IO
  4. #include "IO.h"
  5. #endif
  6.  
  7. #ifndef DEFINITION_Lists
  8. #include "Lists.h"
  9. #endif
  10.  
  11. #ifndef DEFINITION_Memory
  12. #include "Memory.h"
  13. #endif
  14.  
  15. #ifndef DEFINITION_Strings
  16. #include "Strings.h"
  17. #endif
  18.  
  19. #ifndef DEFINITION_StringMem
  20. #include "StringMem.h"
  21. #endif
  22.  
  23. #ifndef DEFINITION_TokenTab
  24. #include "TokenTab.h"
  25. #endif
  26.  
  27. #ifndef DEFINITION_WriteTok
  28. #include "WriteTok.h"
  29. #endif
  30.  
  31. #ifndef DEFINITION_Actions
  32. #include "Actions.h"
  33. #endif
  34.  
  35. Idents_tIdent Actions_ScannerName;
  36. Idents_tIdent Actions_ParserName;
  37.  
  38. typedef struct S_1 {
  39.     Lists_tList Act;
  40.     TokenTab_PosType ActPos;
  41.     Lists_tList Comm;
  42.     TokenTab_PosType CommPos;
  43. } ElmtType;
  44. static Actions_tActionMode ActionMode;
  45. static struct S_2 {
  46.     TokenTab_PosType A[Actions_Close + 1];
  47. } KeyPos;
  48. static struct S_3 {
  49.     ElmtType A[Actions_Close + 1];
  50. } Action;
  51. static struct S_4 {
  52.     Lists_tList A[Actions_Close + 1];
  53. } ActionComm;
  54. static struct S_5 {
  55.     TokenTab_PosType A[Actions_Close + 1];
  56. } ActionCommPos;
  57. static TokenTab_PosType dummyPos;
  58. static void Tab ARGS(());
  59.  
  60. static Strings_tStringIndex *G_1_i;
  61. static CARDINAL *G_2_t;
  62. static IO_tFile *G_3_f;
  63.  
  64. void Actions_PutComment
  65. # ifdef __STDC__
  66. (Actions_tActionMode kind, TokenTab_PosType kp, Lists_tList c, TokenTab_PosType cp)
  67. # else
  68. (kind, kp, c, cp)
  69. Actions_tActionMode kind;
  70. TokenTab_PosType kp;
  71. Lists_tList c;
  72. TokenTab_PosType cp;
  73. # endif
  74. {
  75.   KeyPos.A[kind] = kp;
  76.   ActionComm.A[kind] = c;
  77.   ActionCommPos.A[kind] = cp;
  78. }
  79.  
  80. void Actions_GetComment
  81. # ifdef __STDC__
  82. (Actions_tActionMode kind, TokenTab_PosType *kp, Lists_tList *c, TokenTab_PosType *cp)
  83. # else
  84. (kind, kp, c, cp)
  85. Actions_tActionMode kind;
  86. TokenTab_PosType *kp;
  87. Lists_tList *c;
  88. TokenTab_PosType *cp;
  89. # endif
  90. {
  91.   *kp = KeyPos.A[kind];
  92.   *c = ActionComm.A[kind];
  93.   *cp = ActionCommPos.A[kind];
  94. }
  95.  
  96. void Actions_PutAction
  97. # ifdef __STDC__
  98. (Actions_tActionMode kind, Lists_tList a, TokenTab_PosType ap, Lists_tList c, TokenTab_PosType cp)
  99. # else
  100. (kind, a, ap, c, cp)
  101. Actions_tActionMode kind;
  102. Lists_tList a;
  103. TokenTab_PosType ap;
  104. Lists_tList c;
  105. TokenTab_PosType cp;
  106. # endif
  107. {
  108.   {
  109.     register ElmtType *W_1 = &Action.A[kind];
  110.  
  111.     W_1->Act = a;
  112.     W_1->ActPos = ap;
  113.     W_1->Comm = c;
  114.     W_1->CommPos = cp;
  115.   }
  116. }
  117.  
  118. void Actions_GetAction
  119. # ifdef __STDC__
  120. (Actions_tActionMode kind, Lists_tList *a, TokenTab_PosType *ap, Lists_tList *c, TokenTab_PosType *cp)
  121. # else
  122. (kind, a, ap, c, cp)
  123. Actions_tActionMode kind;
  124. Lists_tList *a;
  125. TokenTab_PosType *ap;
  126. Lists_tList *c;
  127. TokenTab_PosType *cp;
  128. # endif
  129. {
  130.   {
  131.     register ElmtType *W_2 = &Action.A[kind];
  132.  
  133.     *a = W_2->Act;
  134.     *ap = W_2->ActPos;
  135.     *c = W_2->Comm;
  136.     *cp = W_2->CommPos;
  137.   }
  138. }
  139.  
  140. void Actions_WriteActions
  141. # ifdef __STDC__
  142. (Actions_tActionMode kind, IO_tFile f, BOOLEAN Line)
  143. # else
  144. (kind, f, Line)
  145. Actions_tActionMode kind;
  146. IO_tFile f;
  147. BOOLEAN Line;
  148. # endif
  149. {
  150.   if (Action.A[kind].ActPos.Line != 0) {
  151.     if (WriteTok_Language == WriteTok_Modula2) {
  152.       IO_WriteS(f, (STRING)"(* line ", 8L);
  153.       IO_WriteI(f, (LONGINT)Action.A[kind].ActPos.Line, 0L);
  154.       IO_WriteS(f, (STRING)" \"", 2L);
  155.       IO_WriteS(f, WriteTok_SourceFileName.A, 256L);
  156.       IO_WriteS(f, (STRING)"\" *)", 4L);
  157.       IO_WriteNl(f);
  158.     } else {
  159.       if (Line) {
  160.         IO_WriteS(f, (STRING)"# line ", 7L);
  161.         IO_WriteI(f, (LONGINT)Action.A[kind].ActPos.Line, 1L);
  162.         IO_WriteS(f, (STRING)" \"", 2L);
  163.         IO_WriteS(f, WriteTok_SourceFileName.A, 256L);
  164.         IO_WriteC(f, '"');
  165.         IO_WriteNl(f);
  166.       } else {
  167.         IO_WriteS(f, (STRING)"/* line ", 8L);
  168.         IO_WriteI(f, (LONGINT)Action.A[kind].ActPos.Line, 1L);
  169.         IO_WriteS(f, (STRING)" \"", 2L);
  170.         IO_WriteS(f, WriteTok_SourceFileName.A, 256L);
  171.         IO_WriteS(f, (STRING)"\" */", 4L);
  172.         IO_WriteNl(f);
  173.       }
  174.     }
  175.   }
  176.   Actions_WriteSemanticAction(f, Action.A[kind].Act, 0L);
  177. }
  178.  
  179. static void Tab
  180. # ifdef __STDC__
  181. ()
  182. # else
  183. ()
  184. # endif
  185. {
  186.   {
  187.     Strings_tStringIndex B_1 = 1, B_2 = *G_2_t;
  188.  
  189.     if (B_1 <= B_2)
  190.       for (*G_1_i = B_1;; *G_1_i += 1) {
  191.         IO_WriteC(*G_3_f, ' ');
  192.         IO_WriteC(*G_3_f, ' ');
  193.         if (*G_1_i >= B_2) break;
  194.       }
  195.   }
  196. }
  197.  
  198. void Actions_WriteSemanticAction
  199. # ifdef __STDC__
  200. (IO_tFile f, Lists_tList a, CARDINAL t)
  201. # else
  202. (f, a, t)
  203. IO_tFile f;
  204. Lists_tList a;
  205. CARDINAL t;
  206. # endif
  207. {
  208.   CHAR c;
  209.   Strings_tString s;
  210.   Strings_tStringIndex i;
  211.   Strings_tStringIndex i1, i2;
  212.   CHAR Delimiter;
  213.   Strings_tStringIndex *L_1;
  214.   CARDINAL *L_2;
  215.   IO_tFile *L_3;
  216.  
  217.   L_1 = G_1_i;
  218.   G_1_i = &i;
  219.   L_2 = G_2_t;
  220.   G_2_t = &t;
  221.   L_3 = G_3_f;
  222.   G_3_f = &f;
  223.   i1 = 2;
  224.   while (!Lists_IsEmpty(a)) {
  225.     StringMem_GetString((StringMem_tStringRef)Lists_Head(a), &s);
  226.     Lists_Tail(&a);
  227.     i2 = Strings_Length(&s);
  228.     if (Lists_IsEmpty(a)) {
  229.       DEC(i2);
  230.     }
  231.     Tab();
  232.     i = i1;
  233.     while (i <= i2) {
  234.       c = Strings_Char(&s, i);
  235.       INC(i);
  236.       if (c == '\\') {
  237.         IO_WriteC(f, Strings_Char(&s, i));
  238.         INC(i);
  239.       } else if (c == '"' || c == '\'') {
  240.         Delimiter = c;
  241.         IO_WriteC(f, c);
  242.         do {
  243.           c = Strings_Char(&s, i);
  244.           INC(i);
  245.           IO_WriteC(f, c);
  246.           if (WriteTok_Language == WriteTok_C && c == '\\') {
  247.             IO_WriteC(f, Strings_Char(&s, i));
  248.             INC(i);
  249.           }
  250.         } while (!(c == Delimiter));
  251.       } else {
  252.         IO_WriteC(f, c);
  253.       }
  254.     }
  255.     i1 = 1;
  256.   }
  257.   IO_WriteNl(f);
  258.   G_1_i = L_1;
  259.   G_2_t = L_2;
  260.   G_3_f = L_3;
  261. }
  262.  
  263. void Actions_WriteStringList
  264. # ifdef __STDC__
  265. (IO_tFile file, Lists_tList slist)
  266. # else
  267. (file, slist)
  268. IO_tFile file;
  269. Lists_tList slist;
  270. # endif
  271. {
  272.   while (!Lists_IsEmpty(slist)) {
  273.     StringMem_WriteString(file, (StringMem_tStringRef)Lists_Head(slist));
  274.     Lists_Tail(&slist);
  275.   }
  276. }
  277.  
  278. void BEGIN_Actions()
  279. {
  280.   static BOOLEAN has_been_called = FALSE;
  281.  
  282.   if (!has_been_called) {
  283.     has_been_called = TRUE;
  284.  
  285.     BEGIN_TokenTab();
  286.     BEGIN_StringMem();
  287.     BEGIN_Strings();
  288.     BEGIN_Idents();
  289.     BEGIN_IO();
  290.     BEGIN_Lists();
  291.     BEGIN_IO();
  292.     BEGIN_Lists();
  293.     BEGIN_Memory();
  294.     BEGIN_Strings();
  295.     BEGIN_StringMem();
  296.     BEGIN_TokenTab();
  297.     BEGIN_WriteTok();
  298.  
  299.     dummyPos.Line = 0;
  300.     dummyPos.Column = 0;
  301.     for (ActionMode = Actions_Export; ActionMode <= Actions_Close; ActionMode += 1) {
  302.       KeyPos.A[ActionMode] = dummyPos;
  303.       Lists_MakeList(&ActionComm.A[ActionMode]);
  304.       ActionCommPos.A[ActionMode] = dummyPos;
  305.       Lists_MakeList(&Action.A[ActionMode].Act);
  306.       Action.A[ActionMode].ActPos = dummyPos;
  307.       Lists_MakeList(&Action.A[ActionMode].Comm);
  308.       Action.A[ActionMode].CommPos = dummyPos;
  309.     }
  310.   }
  311. }
  312.